package com.hrt.common.systemmanager.systemsetting.dict.data;

import com.btcode.db.sqlparameter.SQLParameterList;
import com.btcode.exception.BusinessException;
import com.btcode.orm.model.IDomainField;
import com.btcode.orm.model.IField;
import com.btcode.orm.model.IModelAddition;
import com.btcode.orm.relation.ex.IRelation;
import com.hrt.common.db.CommonDBManager;
import java.math.BigDecimal;
import java.util.List;

public class BcDictDataModelAddition implements IModelAddition<BcDictDataModel> {

    @Override
    public void generateDefaultValue(BcDictDataModel model) {
        // TODO Auto-generated method stub

    }

    @Override
    public void initField(List<IField> fields) {
        // TODO Auto-generated method stub

    }

    @Override
    public void initRelations(List<IRelation> relations) {
        // TODO Auto-generated method stub

    }

    @Override
    public void initDomainField(List<IDomainField> domainFields) {
        // TODO Auto-generated method stub

    }

    @Override
    public void beforeCreate(BcDictDataModel model) {
        String sql = " SELECT count(1) from c_bc_dict_data where DICT_TYPE_CODE = @DICT_TYPE_CODE and CODE=@CODE";
        SQLParameterList pc = new SQLParameterList();
        pc.put("DICT_TYPE_CODE", model.getDictTypeCode());
        pc.put("CODE", model.getCode());

        Object count = CommonDBManager.getDataExecuter().queryScalar(sql, pc);

        if (count != null && ((BigDecimal) count).intValue() > 0) {
            throw new BusinessException("代码有重复");
        }
    }

    @Override
    public void afterCreate(BcDictDataModel model) {
        // TODO Auto-generated method stub

    }

    @Override
    public void beforeUpdate(BcDictDataModel model) {
        // TODO Auto-generated method stub

    }

    @Override
    public void afterUpdate(BcDictDataModel model) {
        // TODO Auto-generated method stub

    }

    @Override
    public void beforeDelete(BcDictDataModel model) {
        // TODO Auto-generated method stub

    }

    @Override
    public void afterDelete(BcDictDataModel model) {
        // TODO Auto-generated method stub

    }

}
